<?php
class Index_Controller extends Controller {
    public function init() {
		parent::init();
	}
    
    /**
     * Index
     *
     * @AopBefore(Aop_Model, test1)
     * @AopBefore(Aop_Model, test4)
     * @AopAfter(Aop_Model, test2)
     * @AopAround(Aop_Model, test3)
     *
     * @return mixed
     */
    public function indexAction() {
        echo "Hello, world!";
    }
    
    public function testAction() {
        $time = date('Y-m-d H:i:s');
		include(view('test.htm'));
    }

    public function esAction() {
        $settings = [
            'number_of_shards' => 3,
            'number_of_replicas' => 2
        ];
        $properties = [
            'age' => [
                'type' => 'integer'
            ],
            'name' => [
                'type' => 'text',
                'index' => 'true'
            ]
        ];
        $properties2 = [
            'sex' => [
                'type' => 'integer'
            ],
            'email' => [
                'type' => 'text'
            ]
        ];
        $docs = [
            ['id' => 1, 'age' => 39, 'name' => 'Lijia'],
            ['id' => 2, 'age' => 38, 'name' => 'Cathy'],
            ['id' => 3, 'age' => 6, 'name' => 'Yanda']
        ];
        $es = new Es();
        $es->createIndex('users');
        $es->putMapping('users', $properties);
        $es->bulkDoc('users', $docs);
        $result = $es->getDocs('users', [1, 2, 3]);
        print_r($result);
    }

    public function searchAction() {
        $query = [
            'match' => [
                'name' => 'Yanda'
            ]
        ];
        $es = new Es();
        $result = $es->search('users', $query);
        print_r($result);
    }
}
